package com.seed.uaa.web.user;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import com.seed.core.annotation.Col;
import com.seed.core.enumeration.ColumnType;
import com.seed.core.enumeration.YesNo;
import com.seed.core.annotation.BelongsTo;
import com.seed.core.annotation.Habtm;
import com.seed.core.annotation.HasMany;
import com.seed.uaa.web.organization.Organization;
import com.seed.uaa.web.role.Role;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.List;

@Schema(description = "用户")
@Table(value = "uaa_user")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User {
    @Id
    @Schema(title = "ID")
    private String id;

    @Schema(title = "所属部门", description = "用户所在的职能管理部门，也是组织")
    private String organizationId;

    @Schema(title = "姓名")
    private String name;

    @Schema(title = "头像")
    private String avatar;

    @Schema(title = "用户名")
    private String username;

    @Schema(title = "密码")
    private String password;

    @Schema(title = "盐")
    private String salt;

    @Schema(title = "截止日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDateTime expireDate;

    @Schema(title = "是否可用", description = "如果为no,则连下级用户也不能登录，用于主动停止使用系统")
    private YesNo usable;

    @Schema(title = "是否可登录", description = "如果为no,则连下级用户也不能登录，用于被动停止使用系统")
    private YesNo loginable;

    @Schema(title = "是否启用", description = "如果为no,则自己不能登录，不影响下级")
    private YesNo enable;

    @Schema(title = "是否激活", description = "未激活的账号需要先走激活流程")
    private YesNo active;

    @Schema(title = "原因", description = "账号不能登录系统的原因")
    private String reason;

    @Schema(title = "访问权限")
    @Col(type = ColumnType.TEXT, length = 2048)
    private String actions;

    @Schema(title = "数据权限")
    @Col(type = ColumnType.TEXT, length = 2048)
    private String datas;

    @Schema(title = "字段权限")
    @Col(type = ColumnType.TEXT, length = 2048)
    private String fields;

    @Schema(title = "所属租户")
    private String tenantId;

    @Schema(title = "创建时间")
    @Column(onInsertValue = "now()")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;

    @Schema(title = "创建时间")
    @Column(onInsertValue = "now()", onUpdateValue = "now()")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updatedAt;

    @Schema(title = "删除时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime deletedAt;

    @Schema(title = "版本号")
    @Column(version = true)
    private Long version;

    @Schema(title = "角色")
    @Column(ignore = true)
    @Habtm(through = UserRole.class, label = "用户角色", comment = "用户拥有的角色", selfColumn = "id")
    private List<Role> roles;

    @Schema(title = "所属组织")
    @Column(ignore = true)
    @BelongsTo
    private Organization organization;

    @Schema(title = "职位")
    @Column(ignore = true)
    @HasMany(label = "职位", comment = "用户负责的职位", targetColumn = "manager_id")
    private List<Organization> positions;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getOrganizationId() {
        return organizationId;
    }

    public void setOrganizationId(String organizationId) {
        this.organizationId = organizationId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public LocalDateTime getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(LocalDateTime expireDate) {
        this.expireDate = expireDate;
    }

    public YesNo getUsable() {
        return usable;
    }

    public void setUsable(YesNo usable) {
        this.usable = usable;
    }

    public YesNo getLoginable() {
        return loginable;
    }

    public void setLoginable(YesNo loginable) {
        this.loginable = loginable;
    }

    public YesNo getEnable() {
        return enable;
    }

    public void setEnable(YesNo enable) {
        this.enable = enable;
    }

    public YesNo getActive() {
        return active;
    }

    public void setActive(YesNo active) {
        this.active = active;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getActions() {
        return actions;
    }

    public void setActions(String actions) {
        this.actions = actions;
    }

    public String getDatas() {
        return datas;
    }

    public void setDatas(String datas) {
        this.datas = datas;
    }

    public String getFields() {
        return fields;
    }

    public void setFields(String fields) {
        this.fields = fields;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public LocalDateTime getDeletedAt() {
        return deletedAt;
    }

    public void setDeletedAt(LocalDateTime deletedAt) {
        this.deletedAt = deletedAt;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public List<Organization> getPositions() {
        return positions;
    }

    public void setPositions(List<Organization> positions) {
        this.positions = positions;
    }
}
